package com.ybear.wechatpatdemo;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.ybear.patsdk.widget.PatView;
import com.ybear.wechatpatdemo.adapter.PatAdapter;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private PatView pvUserPhoto;
    private RecyclerView rvMsgList;

    private PatAdapter mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initData();
        initListener();
    }

    private void initView() {
        pvUserPhoto = findViewById( R.id.main_pv_user_photo );
        rvMsgList = findViewById( R.id.main_rv_msg_list );
    }

    private void initData() {
        //取消大头像的点击间隔时间
        pvUserPhoto.setIntervalMillis( 0 );

        rvMsgList.setLayoutManager( new LinearLayoutManager( this ) );

        List<PatAdapter.ItemData> dataList = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            PatAdapter.ItemData data = new PatAdapter.ItemData();
            data.setData("测试的聊天信息\n-> 当前是第 " + ( i + 1 ) + " 条信息" );
            data.setMsgType( PatAdapter.MsgType.MSG );
            dataList.add( data );
        }
        mAdapter = new PatAdapter( dataList );
        rvMsgList.setAdapter( mAdapter );
    }

    private void initListener() {
        //拍一拍事件监听器
        mAdapter.setOnPatClickListener(v -> {
            //滑动到底部
            rvMsgList.scrollToPosition( mAdapter.getItemCount() - 1 );
        });
    }
}
